package com.api.server.service.impl;

import com.api.server.pojo.User;
import com.api.server.pojo.UserListPage;
import com.api.server.pojo.Venue;
import com.api.server.mapper.VenueMapper;
import com.api.server.service.IVenueService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author shi
 * @since 2022-04-28
 */
@Service
public class VenueServiceImpl extends ServiceImpl<VenueMapper, Venue> implements IVenueService {

    @Autowired
    private VenueMapper venueMapper;

    @Override
    public Venue message(String venuenumber) {
        return venueMapper.selectById(venuenumber);
    }

    @Override
    public int add(Venue venue) {
        venue.setVenueisfree("是");
        venue.setVenueopen("是");
        venue.setState("true");
        return venueMapper.insert(venue);
    }

    @Override
    public int delete(String id) {
        return venueMapper.deleteById(id);
    }

    @Override
    public List<Venue> equByCdId(String id) {
        return venueMapper.selectList(new QueryWrapper<Venue>().lambda().eq(Venue::getVenuemanagement,id));
    }

    @Override
    public int updataById(Venue venue) {
        return venueMapper.updateById(venue);
    }

    @Override
    public Map<String, Object> page(UserListPage userListPage) {
        Page pageInfo = new Page(userListPage.getPagenum(),userListPage.getPagesize());
        IPage<User> iPage = venueMapper.selectPage(pageInfo,new QueryWrapper<Venue>().lambda().like(Venue::getState,userListPage.getQuery()));
        Map<String,Object> pageMap = new HashMap<>(3);
        //总条数
        pageMap.put("total",iPage.getTotal());
        //总页数
        pageMap.put("pages",iPage.getPages());
        //当前页码
        pageMap.put("pagenum",iPage.getSize());
        //数据集合
        pageMap.put("current_data",iPage.getRecords());

        return pageMap;
    }
}
